package com.itheima.producer;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer_HelloWorld {
    public static void main(String[] args) throws IOException, TimeoutException {
//        1.创建连接工厂
        ConnectionFactory connectionFactory = new ConnectionFactory();
//        2.设置参数
        connectionFactory.setHost("192.168.0.104");//默认值为localhost
        connectionFactory.setPort(5672);//默认值为5672
        connectionFactory.setVirtualHost("/itcast");//默认值为/
        connectionFactory.setUsername("heima");
        connectionFactory.setPassword("heima");
//        创建连接Connection
        Connection connection = connectionFactory.newConnection();
//        创建Channel
        Channel channel =connection.createChannel();
//        创建队列Queue
        /**
         * String queue, boolean durable, boolean exclusive, boolean autoDelete, Map<String, Object> arguments
         * 1.queue:队列名称
         * 2.durable:是否持久化,当mq重启之后,还在
         * 3.exclusive:
         *      * 是否独占,只能有一个消费者监听这队列
         *      *当Connection关闭时,是否删除队列
         * 4.autoDelete:是否自动删除,当没有Consumer时,自动删除
         * 5.arguments:参数
         */
        channel.queueDeclare("hello_world",true,false,false,null);
//        发送消息
        /** basicPublish(String exchange, String routingKey, BasicProperties props, byte[] body)
         *1.exchange交换机名称
         *2. routingKey路由名称
         * 3.props配置信息
         */
        String body="hello rabbitmq...";
        channel.basicPublish("","hello_world",null,body.getBytes());
//        channel.close();
//        connection.close();

    }
}
